<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>新增人员</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/style.css" rel="stylesheet" type="text/css">
<link type="text/css" href="jquery/jquery-ui-1.8.19.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery/jquery.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui-1.8.19.custom.min.js"></script>
<script type="text/javascript" src="script/commons.js"></script>
<script type="text/javascript" src="script/objects.js"></script>
<script type="text/javascript">
var mode = '${mode}';
<c:if test="${modifyUser != null}">
var user = {
	uid : "${modifyUser.uid}",
	uname : "${modifyUser.uname}",
	roleId : "${modifyUser.role.roleId}",
	department : "${modifyUser.department}"
}
</c:if>
$(document).ready(function(e) {
	$("#uid").val("-1");
    if(mode == "modify" && user != null){
		$("#uname").val(user.uname);
		$("#uname").attr("readonly", "readonly");
		$("#roleId").val(user.roleId);
		$("#department").val(user.department);
		$("#uid").val(user.uid);
	}
});
function check() {
	var uname = document.getElementById("uname").value;
	var upwd = document.getElementById("upwd").value;
	var role = document.getElementById("roleId");
	var roleId = role.value;
	with (document.all) {
		if (uname.value == "") {
			alert("用户名不允许为空");
			return false;
		}
		if (mode != "modify" && (upwd.value == "" || againpwd == "")) {
			alert("密码不允许为空");
			return false;
		}
		if (upwd.value != againpwd.value) {
			alert("两次密码输入不一致")
			upwd.value = "";
			againpwd.value = "";
			return false;
		} else {
			document.userAddForm.submit();
		}
	}
}
</script>
</head>
<body>
<html:form method="post" action="useradd.do">
  <div class="button_bar">
    <c:if test="${finuser.role.roleId == 1}">
      <button type="button" class="common_button" onclick="check();"> 保存</button>
    </c:if>
    <button class="common_button" onclick="back();">返回</button>
  </div>
  <table class="query_form_table detail_form_table">
    <tr>
      <th colspan="2">
      <span class="red_star">*</span>为必填项
      <html:hidden property="uid" styleId="uid" />
      </th>
    </tr>
    <tr>
      <th>用户名</th>
      <td><html:text property="uname" styleId="uname" />
        <html:errors property="uname" />
        <span class="red_star">*</span></td>
    </tr>
    <tr>
      <th>密码</th>
      <td><html:password property="upwd" styleId="upwd" />
        <html:errors property="upwd" />
        <span class="red_star">*</span></td>
    </tr>
    <tr>
      <th>重复密码</th>
      <td><html:password property="againpwd" />
        <span class="red_star">*</span></td>
    </tr>
    <tr>
      <th>角色</th>
      <td>
      <html:select property="roleId" styleId="roleId">
        <html:options collection="roles" property="roleId" labelProperty="roleName"/>
      </html:select>
      <span class="red_star">*</span></td>
    </tr>
    <tr>
      <th>所属部门</th>
      <td>
      <html:select property="department" styleId="department">
        <html:options collection="departments" property="departmentName" />
      </html:select>
      <span class="red_star">*</span></td>
    </tr>
  </table>
  <script>
	setCurTime('t1');
	setCurTime('t2');
  </script> 
</html:form>
</body>
</html>